package com.house.core.model;

import org.msgpack.annotation.Ignore;
import org.msgpack.annotation.Index;
import org.msgpack.annotation.Message;

/**
 *
 * 员工表
 * @author <a href="mailto:chong.sun@renren-inc.com">sun chong</a>
 * @version 2013-2-18
 */
@Message
public class Employees{
	@Index(1)
	private long id;
	@Index(2)
	private String username;
	@Index(3)
	private String nickname;
	@Index(4)
	private String password;
	@Index(5)
	private String cardno;
	@Index(6)
	private String address;
	@Index(7)
	private int role;
	/*
	 * 权限值，64位，从低位开始计算，下面是对照表
	 * 1、是否可以登录
	 * 
	 * */
	private long authority;
	private int joiningTraderId;

	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getNickname() {
		return nickname;
	}
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getCardno() {
		return cardno;
	}
	public void setCardno(String cardno) {
		this.cardno = cardno;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public Role getRole() {
		return Role.valueOf(role);
	}
	public void setRole(Role role) {
		this.role = role.getValue();
	}
	public long getAuthority() {
		return authority;
	}
	public void setAuthority(long authority) {
		this.authority = authority;
	}
	public int getJoiningTraderId() {
		return joiningTraderId;
	}
	public void setJoiningTraderId(int joiningTraderId) {
		this.joiningTraderId = joiningTraderId;
	}
	
	@Override
	public String toString() {
		return "Employees [id=" + id + ", username=" + username + ", nickname="
				+ nickname + ", password=" + password + ", cardno=" + cardno
				+ ", address=" + address + ", role=" + role + ", authority="
				+ authority + ", joiningTraderId=" + joiningTraderId + "]";
	}
	
	/**
	 * 员工是否可以登录
	 * @return
	 */
	public boolean canLogin(){
		return (authority & 0x1) == 1;
	}

	@Message
	public enum Role  {
		ADMINISTRATOR(1),
		EMPLOYEES(2), 
		SHOP_MANAGER(3), 
		;
		private int value;
		private Role(int value){
			this.value = value;
		}
		public int getValue() {
			return value;
		}

		public static Role valueOf(int value) {
			switch (value) {
			case 1:
				return ADMINISTRATOR;
			case 2:
				return EMPLOYEES;
			case 3:
				 return SHOP_MANAGER;
			default:
				return null;
			}
		}
	}
}
